﻿$(function () {
    warehouseFan()
});
//仓库详情
function warehouseFan() {
    layui.use('layer', function () {
        var form = layui.form;

        var warehouseID = localStorage["warehouseID"]
        // 创建表格实例
        $.ajax({
            url: "/Warehouses/LedgerInfowarehouseFan",
            type: "get",
            data: {
                warehouseID: warehouseID,
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                $(data.data).each(function () {
                    $("#warehouseNumber").text(this.warehouseNumber)
                    $("#warehouseName").text(this.warehouseName)
                    localStorage["warehouseName"] = this.warehouseName
                    $("#warehouseArea").text(this.warehouseArea)
                    $("#selectWarehouseArea").text(this.selectWarehouseArea)
                    $("#positionNumber").text(this.positionNumber)
                    $("#principal").text(this.principal)
                    $("#warehouseState").text(this.warehouseState==1?"正常":"异常")
                    $("#warehouseRemark").text(this.warehouseRemark)
                   
                    form.render();
                })
            }
        });
    })
    //本仓库的库区显示
    ParticularsShowReservoir()
    //本仓库的库区的全部库位显示
    ParticularsShowSupplier()
}
//本仓库的库区显示
function ParticularsShowReservoir() {
    layui.use(function () {
        var table = layui.table;
        var warehouseNames = localStorage["warehouseName"]
        console.log(table)
        // 先进行表格的初始渲染
        table.render({
            elem: '#ShowReservoir',  // 表格元素的选择器
            page: {
                limit: 5,
                limits: [5, 8, 10]
            },
            cols: [[
                { field: 'reservoirId', title: '序号' },
                { field: 'reservoirName', title: '仓区名称' },
                { field: 'reservoirNumber', title: '仓区编号' },
                { field: 'reservoirArea', title: '面积' },
                { field: 'reservoirArea', title: '库位数量' },
                { field: 'reservoirRemark', title: '备注' }
            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });
        // 创建表格实例
        $.ajax({
            url: "/Warehouses/LedgerInfoParticularsShowReservoir",
            type: "get",
            data: {
                pageindex: 1,
                pagesize: 100,
                warehouseName: warehouseNames
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data.plist);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                table.reload('ShowReservoir', {
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    data: data.data.plist
                });
            },
            error: function () {
                console.log("请求失败");
            }
        });
    });
}
//本仓库的库区的全部库位显示
function ParticularsShowSupplier() {
    layui.use(function () {
        var table = layui.table;
        var warehouseName = localStorage["warehouseName"]
        console.log(table)
        // 先进行表格的初始渲染
        table.render({
            elem: '#ShowSupplier',  // 表格元素的选择器
            page: {
                limit: 5,
                limits: [5, 8, 10]
            },
            cols: [[
                { field: 'locationId', title: '序号' },
                { field: 'locationName', title: '仓位名称' },
                { field: 'locationNumber', title: '仓位编号' },
                { field: 'locationArea', title: '面积' },
                { field: 'locationweight', title: '最大载重量' },
                { field: 'locationweight', title: '库位数量' },
                { field: 'locationRemark', title: '备注' }
            ]],
            // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
            data: []
        });
        // 创建表格实例
        $.ajax({
            url: "/Warehouses/LedgerInfoParticularsShowSupplier",
            type: "get",
            data: {
                pageindex: 1,
                pagesize: 100,
                warehouseName: warehouseName
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data.dtoList);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                table.reload('ShowSupplier', {
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    data: data.data.plist
                });
            },
            error: function () {
                console.log("请求失败");
            }
        });
    });
}
